const path = require("path");
const HtmlWebpackPlugin = require('html-webpack-plugin');
const webpack = require('webpack')
const VueLoaderPlugin = require('vue-loader/lib/plugin')

module.exports = {
    entry: {
        main: './src/main.js'
    },
    output: {
        filename: '[name]-[hash:8].bundle.js',
        path: path.join(__dirname, "dist")
    },
    module: {
        rules: [{
            test: /\.less?$/,
            use: [
                'vue-style-loader',
                'css-loader',
                'less-loader'
            ]
        }, {
            test: /\.vue$/,
            use: ['vue-loader']
        }, {
            test: /\.(png|jpg|gif)$/,
            use: {
                loader: 'url-loader',
                options: {
                    limit: 10 * 1024,
                    esModule: false
                }
            }
        }, {
            test: /\.js$/,
            exclude: /node_modules/,
            use: {
                loader: 'babel-loader',
                options: {
                    presets: [
                        ['@babel/preset-env', {
                            "useBuiltIns": "entry",
                            "corejs": 3
                        }]
                    ]
                }
            }
        }, {
            test: /\.(js|vue)$/,
            exclude: /node_modules/,
            use: {
                loader: "eslint-loader",
                options: {
                    fix: true,
                }
            },
            enforce: "pre",

        }],
    },
    plugins: [
        new HtmlWebpackPlugin({
            title: 'Webpack Sample',
            template: './public/index.html',
        }),
        new webpack.DefinePlugin({
            BASE_URL: '"./public/"'
        }),
        new VueLoaderPlugin()
    ]
};